package cn.zwk.config;

import lombok.experimental.UtilityClass;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

@UtilityClass
public class ConfigLoader {
    public static PipelineConfig load(Path yamlPath) {
        try (InputStream in = Files.newInputStream(yamlPath)) {
            Yaml yaml = new Yaml(new Constructor(PipelineConfig.class, new LoaderOptions()));
            PipelineConfig cfg = yaml.load(in);
            return cfg == null ? new PipelineConfig() : cfg;
        } catch (IOException e) {
            throw new RuntimeException("Failed to read config: " + yamlPath, e);
        }
    }
}
